Array of Ints not returning values

I am attempting to make an array of column widths for columns in a DOORS table using the code below:

// o has already been determined to be a table object
// rowObj and cellObj are generic objects initialized to null
// NumberOfColumns is a function that returns the number of columns in a table

// Create the array
Array columnWidths = create(NumberOfColumns(o), 0)

// Populate the column widths array
colNo = 0
for rowObj in o do
{
    for cellObj in rowObj do
    {
        put(columnWidths, getCellWidth cellObj, colNo, 0)
        
        // I'm using this line for debugging. it prints out "closed" for the values
        // I am trying to retrieve from the array.
        print colNo " - " get(columnWidths, colNo, 0) NL
        
        colNo++
    }
    
    // Make only one pass
    break
}

I haven't been able to get the values back out of the array. Can anyone point out what I'm doing wrong here? Thanks!


CMusicFan - Tue Sep 29 16:21:31 EDT 2015

Re: Array of Ints not returning values
llandale - Wed Sep 30 10:16:55 EDT 2015

[1] Types.

The Array does not remember what the type of data is being stored.  You must:

  • Be consistent when inserting; which almost always means you know what type of data is in each column.  In this case type "int".
  • ALWAYS cast the data when you retrieve it.
    • (int get(columnWidths, colNo, 0))
  • So your print statement becomes
    • print colNo " - " (int get(columnWidths, colNo, 0)) NL

I'm guessing the default retrieve type is "string", if so it is interpreting your integer "110" as some kind of address in the string table.

[2] Create.  I always create my arrays with (1,1).  They automatically expand.  Not sure what happens when you create with (4,0).

[3] I think you want a Skip list anyway.

  • Skip skpWidths = create()   // KEY: 'int' Column Number; DATA: 'int' width (pixels?)
  • ...
  • put(skpWidths, colNo, getCellWidth(cellObj))
  • ...
  • int iWidth
  • get(skpWidths,colNo, iWidth))
  • print colNo " - " iWidth NL

The "get" of the Skip is implicitely cast by the type of data in the "get" statement (iWidth).

-Louie

Re: Array of Ints not returning values
CMusicFan - Wed Sep 30 10:44:39 EDT 2015

I can't believe I missed the fact that I was creating an array with no y-axis...that explains a lot. Thank you so much for the help! I'll give some thought into using a skip list instead of an array as well. Thanks!